<template>
  <div class="app-container">
    <div class="custom_card_0">
      <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px" size="small">
        <el-form-item label="时间">
          <el-date-picker clearable size="small" v-model="statisticTime" type="daterange" range-separator="至" value-format="yyyy-MM-dd" start-placeholder="开始时间" end-placeholder="结束时间" @change="timeChange"></el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
    </div>


    <div class="custom_card">
      <el-row class="mb8" :gutter="10">

        <right-toolbar
          :showSearch.sync="showSearch"
          @queryTable="handleQuery"
        ></right-toolbar>
      </el-row>
      <el-table
        v-loading="loading"
        :data="basicList"
        stripe
        :header-cell-style="{ background: '#eef1f6', color: '#606266' }" border>
        <template slot="empty">
          <el-empty :image-size="50" description="暂无渠道统计信息"></el-empty>
        </template>
        <el-table-column
          align="center"
          prop="contractNo"
          label="渠道"
          min-width="180">
        </el-table-column>
        <el-table-column
          align="center"
          prop="businessType"
          label="访问客户数"
          min-width="180">
          <template slot="header">
               <span>访问客户数</span>
            <el-tooltip class="item" effect="dark" content="统计筛选时间内访问小程序的渠道客户数,一位客户多次访问计为1" placement="top">
              <i class="el-icon-question" style="color: #0d65eb"></i>
            </el-tooltip>
          </template>
          <template v-slot="{row}">
            {{row.businessType|contractType}} - {{row.contractSource==1?'线下合同':'线上合同'}}
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          prop="orderNo"
          label="转化成功数"
          min-width="180">
          <template slot="header">
            <span>转化成功数</span>
            <el-tooltip class="item" effect="dark" content="统计筛选时间内成为小程序客户的渠道客户数" placement="top">
              <i class="el-icon-question" style="color: #0d65eb"></i>
            </el-tooltip>
          </template>
          <template v-slot="{row}">
            <el-button type="text">{{row.orderNo}}</el-button>
          </template>
        </el-table-column>

        <el-table-column
          align="center"
          prop="enterpriseCertificationName"
          label="转化率"
          min-width="180">
          <template slot="header">
            <span>转化率</span>
            <el-tooltip class="item" effect="dark" content="转化率=转化成功数/访问客户数" placement="top">
              <i class="el-icon-question" style="color: #0d65eb"></i>
            </el-tooltip>
          </template>
        </el-table-column>

      </el-table>

      <pagination :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
                  @pagination="getList"/>
    </div>

  </div>
</template>

<script>

import {contractList, updateContractStatus} from "@/api/contract/contract";

export default {
  data() {
    // 这里存放数据
    return { // 加载标识
      loading: false,
      showSearch:true,
      // 总条数
      total: 0,
      // 工单数据
      basicList: [],
      statisticTime:[],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        startTime:'',
        endTime:''
      },
    }
  },
  // 方法集合
  methods: {
    resetQuery() {
      this.statisticTime=[];
      this.$refs.queryForm.resetFields();
      this.handleQuery();
    },
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    getList() {
      this.loading = true;
      contractList(this.queryParams).then(res => {
        this.loading = false;
        this.total = res.total;
        this.basicList = res.rows;
      }).catch(() => {
        this.loading = false;
      })
    },

    timeChange(e){
      this.queryParams.startTime = e[0];
      this.queryParams.endTime = e[1];
      this.handleQuery();
    }
  },
  // 生命周期 - 挂载完成（可以访问 DOM 元素）
  mounted() {
    this.getList();
  },

}
</script>

<style lang="scss" scoped>
</style>
